﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using XStudio.XCRF.Data.Business.Archieve;

namespace XStudio.XCRF.Data.Entities
{
    /// <summary>
    /// 实体基类
    /// </summary>
    /// <typeparam name="T">具体类型</typeparam>
    public abstract partial class BaseEntity<T> where T : BaseEntity<T>
    {
        /// <summary>
        /// 主键
        /// </summary>
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid ID { get; set; }

        /// <summary>
        /// 记录是否删除
        /// </summary>
        public bool IsDeleted { get; set; }

        [Timestamp]
        [ConcurrencyCheck]
        internal byte[] TimeSpan { get; set; }

        /// <summary>
        /// 关联主记录ID
        /// </summary>
        [ForeignKey("Master")]
        public Guid? MasterID { get; set; }

        /// <summary>
        /// 关联主记录
        /// </summary>
        [InversePropertyAttribute("Archives")]
        public virtual T Master { get; set; }

        /// <summary>
        /// 关联历史记录集合
        /// </summary>
        public virtual ICollection<T> Archives { get; set; }

        /// <summary>
        /// 创建者ID
        /// </summary>
        [ArchieveField]
        [ForeignKey("Creater")]
        public Guid? CreaterID { get; set; }

        /// <summary>
        /// 创建者
        /// </summary>
        public virtual Member Creater { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [ArchieveField]
        [Required]
        [DataType(DataType.DateTime)]
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 最近修改者ID
        /// </summary>
        [ArchieveField]
        [ForeignKey("LastModifier")]
        public Guid? LastModifierID { get; set; }

        /// <summary>
        /// 最近修改者ID
        /// </summary>
        public virtual Member LastModifier { get; set; }

        /// <summary>
        /// 最近修改时间
        /// </summary>
        [ArchieveField]
        [Required]
        [DataType(DataType.DateTime)]
        public DateTime LastModifyTime { get; set; }
    }
}
